const cloud = require('wx-server-sdk');

// 初始化云开发
cloud.init({
  env: 'liucheng-2gmqvcgs50e86304' // 使用指定的云环境
});

// 初始化数据库
const db = cloud.database();

exports.main = async (event, context) => {
  const { orderNumber } = event;

  try {
    const result = await db.collection('Parts').where({
      orderNumber: orderNumber
    }).get();
    
    return {
      success: true,
      data: result.data
    };
  } catch (err) {
    console.error('Error fetching parts by order number:', err);
    return {
      success: false,
      errorMessage: err
    };
  }
};
